/*
io_config.h
io_config.c file headfile
designed by lunanting
-------------------------
2020-03-20 17:14:53
create file
-------------------------
*/
#ifndef __IO_CONFIG_H
#define __IO_CONFIG_H

#include "base_type.h"
#include "canopen/io_board_api.h"
#include "aos/hal/gpio.h"

#define BOARD_IO_CRL_MAX_DATA           (0x00FFFFFF)    //传输给子板注册设备移动数据最大值
#define MAX_REG_DEV_NUMS                (6)             //子板支持的最大设备注册数量

#define xp_io_output_set xp_io_write_pin

/********************need define*******************/
extern void xp_input_event_deal(const uint8_t board_id,const u32 io_state);  //input event deal
extern void xp_output_default_set(void);   //set gpio default output state


/*****************************extern function***********************/
extern void xp_io_board_state_check(const uint8_t board_id,const io_board_state_t state);   //io board online state check
extern void xp_input_change_callback(const uint8_t board_id,const uint8_t len,const uint8_t *state);    //io board input state change callback
extern int xp_io_manage_init(u8 num);    //io manage init
extern void xp_io_write_pin(const uint8_t board_id,const uint8_t pin,const bool state);   //set io board DO state
extern void xp_io_write_pins(const u8 board_id,u32 states,u8 start_pin,u8 pins); //write pins
extern int xp_io_write_pins_rt(const u8 board_id,u32 states,u8 start_pin,u8 pins);
extern u8 xp_io_read_input_pin(const u8 board_id,const u8 pin); //get io input state
extern int xp_io_read_input_pins(const u8 board_id,u32 *states,u8 start_pin,u8 pins);//get io inputs state, added by maoxinfeng
extern u8 xp_io_read_output_pin(const u8 board_id,const u8 pin);    //get io output state
extern u8 xp_io_read_output_pin_real(const u8 board_id,const u8 pin);
extern u32 xp_io_read_output_pins_real(const u8 board_id,u8 start_pin,u8 pins);
extern int xp_io_init(gpio_dev_t *gpio,char *io,u8 num);    //io init 
extern int xp_io_DO_default_set(u8 id,u8 sta);   //io default output set
extern void xp_DO_test(int blink);   //ouput test
extern int xp_output_set_safe(const u8 board_id,u32 states,u8 start_pin,u8 pins);
extern int xp_io_debug(char *type,char *fun,char *param);  //io debug
// extern int xp_io_set_pulse_mode(uint8_t board_id, uint32_t pin_bit_id);
extern int xp_io_clear_pulse(uint8_t board_id, uint32_t pin_id);
extern int xp_io_get_pulse(uint8_t board_id, uint8_t pin_id, uint32_t * const pResult);
extern void xp_io_boardPowerAPI_set(void (*api)(void)); //io board power manage api set
extern int xp_io_config_crl_pin(uint8_t board_id, uint8_t pin_zero, uint8_t pin_pulse, uint8_t pin_CW, uint8_t pin_CCW);
extern int xp_io_set_dev_move_time(uint8_t board_id, uint8_t dev_id, int8_t dir, uint32_t time_ms);
extern int xp_io_set_dev_move_pos(uint8_t board_id, uint8_t dev_id, int32_t move_pos);
extern int32_t xp_io_get_dev_encoder(uint8_t board_id, uint8_t dev_id, int32_t * const pResult);
extern int xp_io_clear_encoder(uint8_t board_id, uint8_t dev_id);
extern uint8_t xp_io_get_register_dev_num(uint8_t board_id);
extern bool xp_io_get_online_sta(uint8_t board_id);

#endif

//end of the file
